
# generate figure 3

library(rio) # to load data
library(tidyverse) # to reshape data
library(lmtest) # to cluster standard errors
library(sandwich) # to cluster standard errors
library(ggeffects) # to plot results

# set your working directory
setwd("~/replication_files")

# load models
source("03_generate_table1.R")

# make predictions with clustered standard errors
# based on model 4 of table 1

# figure 3
predictions1 <- ggpredict(probit4, terms = c("resource_rents_perc_lag","iso3c[all]"), vcov_fun = "vcovHC",
                          vcov_type = "HC0", 
                          vcov_args = list(cluster = monthly_data$iso3c))
plot(predictions1, grid = T) +
  scale_fill_manual(values=c("#000000","#000000","#000000","#000000","#000000","#000000","#000000","#000000","#000000","#000000",
                             "#000000","#000000","#000000","#000000","#000000","#000000","#000000","#000000","#000000","#000000",
                             "#000000","#000000")) + 
  scale_color_manual(values=c("#000000","#000000","#000000","#000000","#000000","#000000","#000000","#000000","#000000","#000000",
                              "#000000","#000000","#000000","#000000","#000000","#000000","#000000","#000000","#000000","#000000",
                              "#000000","#000000")) + 
  labs(y = "Predicted Probability of Debt Issuance", x = bquote(`Resource Rents, % of GDP `[t-1]),
       title = " ") + theme_classic() +
  theme(axis.text = element_text(size = 12), plot.title = element_text(face = "bold"),
        axis.title = element_text(size = 12)) + scale_x_continuous(breaks = pretty_breaks()) +
  scale_y_continuous(limits = c(0,1), labels = percent)

ggsave("figures/figure3.pdf", height = 10, width = 8)
